package org.springframework.boot;

import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;

/**
 * @author shiminghui
 * @date 2025/5/7 20:57
 * @description: TODO
 */
public class Step4 {
    public static void main(String[] args) throws IOException {

        ApplicationEnvironment env = new ApplicationEnvironment();

        env.getPropertySources().addLast(new ResourcePropertySource(new ClassPathResource("step4.properties")));

        ConfigurationPropertySources.attach(env); // 会处理配置文件里面的key-value,然后将处理后的源放到 propertySources集合的最前面

        for (PropertySource<?> ps : env.getPropertySources()) {
            System.out.println(ps.getName());
        }


        // 默认情况下,key要与配置文件里面的key一致才能找到,但是有一个propertySource可以将key的格式统一为以-分割的形式
        System.out.println(env.getProperty("test.xiao-ming"));
        System.out.println(env.getProperty("test.xiao-wang"));
        System.out.println(env.getProperty("test.xiao-li"));


    }
}
